function delNotice(){
    var checks = new Array();
    checks = $('input[type="checkbox"]:checked').map(function(){

        return $(this).val();

    }).get()
    console.log(checks);
    if (checks.length == 0){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "请至少选中一行数据进行操作"
        });
    }else {
        layer.confirm('确定要删除吗?',{icon: 3, title: '系统提示'}, function(index){
            for (var i = 0;i<checks.length;i++){
                var id = checks[i];
                $.ajax({
                    type : 'POST',
                    url : '/delNotice',
                    data : {id:id},
                    success:function (data) {
                        if (data == "OK"){
                            window.location.href = window.location.href;
                        }else {
                            layer.open({
                                title: '提示信息',
                                anim: 0,
                                resize:false,//是否可以拉伸  默认true
                                icon: 2,
                                shadeClose: true,
                                skin: 'layui-layer-molv',
                                content: data
                            });
                        }
                    },
                    error: function (e) {
                        console.log(e)
                    }
                });

            }
            layer.close(index);
        });
    }
}

function editNotice(){
    var theme = $("#theme").val();
    var content = $("#content").val();
    var id = $("#id").val();
    var protocol = window.location.protocol;
    var host = window.location.host;
    if (theme == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "主题不能为空！",
            yes:function (index){
                $('#theme').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (content == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "内容不能为空！",
            yes:function (index){
                $('#content').focus();
                layer.close(index);
            }
        });
        return "";
    }

    $.ajax({
        type : 'POST',
        url : '/editNotice',
        data : {id:id,theme:theme,content:content},
        success:function (data) {
            if (data == "OK"){
                layer.msg('修改成功', {
                    icon: 1,
                    shadeClose: true,
                    skin: 'layui-layer-molv',
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function(){
                    window.location.href = protocol+"//"+host+"/notice";
                });
            }else {
                layer.open({
                    title: '提示信息',
                    anim: 0,
                    resize:false,//是否可以拉伸  默认true
                    icon: 2,
                    shadeClose: true,
                    skin: 'layui-layer-molv',
                    content: data
                });
            }
        },
        error: function (e) {
            console.log(e)
        }
    });
}

function upNotice(diarycontent){
    layer.confirm('确定上架吗?',
        {icon: 3, title: '系统提示'},
        function (index) {
            var id = diarycontent;
            $.ajax({
                type : 'POST',
                url : '/upNotice',
                data : {id:id},
                success:function (data) {

                    if (data == "OK"){
                        layer.msg('上架成功', {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            window.location.href = window.location.href;
                        });
                    }else {
                        layer.open({
                            title: '提示信息',
                            anim: 0,
                            resize:false,//是否可以拉伸  默认true
                            icon: 2,
                            shadeClose: true,
                            skin: 'layui-layer-molv',
                            content: data
                        });
                    }
                },
                error: function (e) {
                    console.log(e)
                }
            });
            layer.close(index);
        });
}

function downNotice(diarycontent){
    layer.confirm('确定下架吗?',
        {icon: 3, title: '系统提示'},
        function (index) {
            var id = diarycontent;
            $.ajax({
                type : 'POST',
                url : '/downNotice',
                data : {id:id},
                success:function (data) {

                    if (data == "OK"){
                        layer.msg('下架成功', {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            window.location.href = window.location.href;
                        });
                    }else {
                        layer.open({
                            title: '提示信息',
                            anim: 0,
                            resize:false,//是否可以拉伸  默认true
                            icon: 2,
                            shadeClose: true,
                            skin: 'layui-layer-molv',
                            content: data
                        });
                    }
                },
                error: function (e) {
                    console.log(e)
                }
            });
            layer.close(index);
        });
}